package com.esm.tool;

import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.esm.app.MyApplication;
import com.esm.netity.Badlynetity;
import com.esm.view.MainActivity;
import com.esm.view.R;

import java.util.List;

@SuppressLint("NewApi")
public class PadAdapter extends BaseAdapter {
    private MainActivity mContext = null;
    private List<Badlynetity> mData;
    private ViewHolder holder;

    public PadAdapter(MainActivity lushuUtils, List<Badlynetity> data) {
        mContext = lushuUtils;
        mData = data;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    public void setData(List<Badlynetity> mData) {
        this.mData = mData;
    }


    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_gv_image, parent, false);
            holder = new ViewHolder();
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.tv_num = (TextView) convertView.findViewById(R.id.tv_num);
            holder.tv_anm = (TextView) convertView.findViewById(R.id.tv_anm);
            holder.ll = (LinearLayout) convertView.findViewById(R.id.ll);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (MyApplication.yy.equals("zh"))
            holder.tv_name.setText(mData.get(position).getName());
        else if (MyApplication.yy.equals("en"))
            holder.tv_name.setText(mData.get(position).getNameen());
        else
            holder.tv_name.setText(mData.get(position).getNamevi());
        holder.tv_num.setText(mData.get(position).getNum() + "");

        Drawable btnDrawable = mContext.getResources().getDrawable(R.drawable.shape_bg);
        holder.ll.setBackground(btnDrawable);

        if (mData.get(position).getZt().equals("1"))
            holder.tv_anm.setVisibility(View.VISIBLE);
        else
            holder.tv_anm.setVisibility(View.GONE);
        return convertView;

    }

    static final class ViewHolder {
        TextView tv_num, tv_name, tv_anm;
        LinearLayout ll;
    }

}
